<template>
  <el-form :model="form" status-icon :rules="rules" ref="form" lable-width="100px" class="login-container">


    <h3 class="login-title">系统登录</h3>
    <el-form-item label="用户名" label-width="80px" prop="username" class="username">
      <el-input type="input" v-model="form.username" autocapitalize="off" placeholder="请输入账号"></el-input>

    </el-form-item>


    <el-form-item label="密码" label-width="80px" prop="password" class="password">

      <el-input type="password" v-model="form.password" autocapitalize="off" placeholder="请输入密码"></el-input>

    </el-form-item>

    <el-form-item class="login_tite">
      <el-button type="primary" @click="login" class="login_button">
        登录
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script>
// import Mock from 'mockjs'
// import mock from 'mockjs'
import { getMen } from '../../../api/data.js'
export default {
  name: 'MagementLogin',

  data() {
    return {
      form: {


      },
      rules: {
        username: [
          {
            required: true, message: "请输入用户名", trigger: 'blur'

          },
          {
            min: 3,
            message: "用户名长度不能少于3位",
            trigger: 'blur'
          }


        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: 'blur'
          },
          {
            min: 5,
            message: "密码长度不能少于5位",
            trigger: 'blur'
          }

        ]
      }

    };
  },

  mounted() {

  },

  methods: {
    login() {
      getMen(this.form).then(({ data: res }) => {
        
        if (res.code === 20000) {
          this.$store.commit('clearMenmu')
          this.$store.commit('setmenu', res.data.menu)
          this.$store.commit('setToken', res.data.token);

          this.$store.commit('addMenu', this.$router)
          this.$router.push({ name: 'home' });

        } else {
          // this.$message.warning(res.data.message)
        }
      })

      // console.log(token);
      // this.$store.commit('setToken', token);
      // this.$router.push({name:'Main'});

    }
  },
};
</script>

<style lang="less" scoped>
.login-container {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background-color: #fff;
  border: 1px solid #eaeaea;

  h3 {
    text-align: center;
  }

  .login_tite {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;

    .login_button {
      margin: 10px auto
    }
  }
}
</style>